package com.richard.dev.common.activity;

import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.TypeReference;
import com.richard.library.basic.basic.BasicActivity;
import com.richard.library.basic.util.LogUtil;
import com.richard.library.http.dict.RequestType;
import com.richard.library.http.request.RequestBuilder;
import com.richard.library.simplerx.XObservable;
import com.richard.library.simplerx.XObservableOnSubscribe;
import com.richard.library.simplerx.XSubscribe;

/**
 * @author: Administrator
 * @createDate: 2022/3/22 17:18
 * @version: 1.0
 * @description: 描述
 */
@Route(path = "/test/request")
public class TestRequestActivity extends BasicActivity {

    @Override
    public void initLayoutView() {
        TextView textView = new TextView(getContext());
        textView.setText("测试");
        setContentView(textView);
    }

    @Override
    public void initData() {
        navigationbar.setVisibility(View.VISIBLE);
        navigationbar.setTitle("Request");
        navigationbar.setTitleTextViewShow(true);


        XObservable.create(new XObservableOnSubscribe<String>() {
                    @Override
                    public String run() throws Throwable {
                        return RequestBuilder.init(RequestType.GET)
                                .setUrl("http://www.baidu.com")
                                .build()
                                .request(new TypeReference<String>() {
                                });
                    }
                })
                .bindLife(this)
                .toAsyncSubscribe(new XSubscribe<String>() {
                    @Override
                    public void onXNext(String data) {
                        LogUtil.dTag("testtt", data);
                        getUIView().showMsgDialog(data,null);
                    }

                    @Override
                    public void onXError(Throwable e) {
                        LogUtil.dTag("testtt", e);
                        getUIView().showMsgDialog(e.getMessage(),null);
                    }
                });
    }

    @Override
    public void bindListener() {

    }
}
